package diko_parent.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.diko.commonUtils.R;
import diko_parent.eduservice.entity.EduCourse;
import diko_parent.eduservice.entity.Teacher;
import diko_parent.eduservice.service.EduCourseService;
import diko_parent.eduservice.service.TeacherService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Emma Li
 * @date 2020/10/21 - 9:48
 */
@RestController
//@CrossOrigin
@RequestMapping("/eduservice/teacherfront")
public class FrontTeacherController {
    @Autowired
    private TeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

        @ApiOperation(value="分页讲师列表")
        @GetMapping(value="{page}/{limit}")
        public R pageList(
                @ApiParam(name="page",value = "当前页码",required = true)
                @PathVariable Long page,

                @ApiParam(name="limit",value = "每页记录数",required = true)
                @PathVariable Long limit
        ){
            Page<Teacher> pageParam = new Page<>(page, limit);
            Map<String, Object> map = teacherService.pageListWeb(pageParam);

            return R.ok().data(map);
        }

        @ApiOperation(value = "根据ID查询讲师")
        @GetMapping(value = "{id}")
        public R getById(
                @ApiParam(name="id",value = "讲师ID",required = true)
                @PathVariable String id
        ){
            //查询讲师信息
            Teacher teacher = teacherService.getById(id);

            //根据讲师id查询这个讲师的课程列表
            List<EduCourse> courseList = courseService.selectByTeacherId(id);

            return R.ok().data("teacher",teacher).data("courseList",courseList);
        }
}
